﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Entities;


namespace DAL
{
    public class GIOHANG_DAL
    {
        public List<GIOHANG_Entities> ItemCollection = new List<GIOHANG_Entities>();

        public void Add(GIOHANG_Entities item)
        {
            for (int i = 0; i < ItemCollection.Count; i++)
            {
                if (item.STT_sanpham == ItemCollection[i].STT_sanpham)
                {
                    ItemCollection[i].SOLUONG += item.SOLUONG;
                    ItemCollection[i].THANHTIEN += item.GiaBan;
                    return;
                }
            }
            ItemCollection.Add(item);
        }
        public void Delete(GIOHANG_Entities item) 
        {
 
            for (int i = 0; i < ItemCollection.Count; i++) 
            {
                if (item.STT_sanpham == ItemCollection[i].STT_sanpham)
                { 
                    ItemCollection.RemoveAt(i); 
                    return; 
                } 
            } 
        }
        public void Update(GIOHANG_Entities item)
        {
            for (int i = 0; i < ItemCollection.Count; i++)
            {
                if (item.STT_sanpham == ItemCollection[i].STT_sanpham)
                {
                    ItemCollection[i].SOLUONG = item.SOLUONG;
                    return;
                }
            }
        }
        public double Total()
        {
            double total = 0;
            for (int i = 0; i < ItemCollection.Count; i++)
            {
                total += ItemCollection[i].THANHTIEN;
            }
            return total;
        }
    }
}
